import { ss } from '@/utils/storage';

const LOCAL_NAME = 'userStorage';

export interface UserInfo {
  avatar: string;
  name: string;
  userBalance: number;
  userGrade: string;
  userName: string;
}

export interface UserState {
  userInfo: UserInfo;
  tenantId: string;
  adminRule: string;
}

export function defaultSetting(): UserState {
  return {
    userInfo: {
      avatar: '',
      name: '',
      userBalance: 0,
      userGrade: '0',
      userName: ''
    },
    tenantId: '',
    adminRule: ''
  };
}

export function getLocalState(): UserState {
  const localSetting: UserState | undefined = ss.get(LOCAL_NAME);
  return { ...defaultSetting(), ...localSetting };
}

export function setLocalState(setting: UserState): void {
  ss.set(LOCAL_NAME, setting);
}
